package Util;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

public class ShareRefUtil {
	
	private static final String TAG = "ShareRefUtil";

	public static String getPref(Context context,String key, String defValue){
		if (context == null) 
			throw new IllegalArgumentException("'context' must not be null.");
		
		Log.v(TAG, "begin get String shared preferences");
		
		SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
		return sharedPreferences.getString(key, defValue);
	}
	
	public static Boolean setPref(Context context,String key, String value){
		if (value == null || value.length() == 0) {
			throw new IllegalArgumentException("'value' must not be null.");
		}
		SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
		
		SharedPreferences.Editor edit = sharedPreferences.edit();
		edit.putString(key, value);
		return edit.commit();
	}
	
	public static Boolean CleanPre(Context context){
		SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
		SharedPreferences.Editor edit = sharedPreferences.edit();
		return edit.clear().commit();
	}
	public static Boolean Remove(Context context, String key){
		SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
		SharedPreferences.Editor edit = sharedPreferences.edit();
		return edit.remove(key).commit();
	}

}
